package Test_0814.ioperations;

import Test_0814.book.Book;
import Test_0814.book.BookShelf;

import java.util.Scanner;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 * Dare: 2024-08-15
 * Time: 9:35
 */
public class BorrowOperation implements IoPeration{
    public void work(BookShelf bookshelf){
        System.out.println("借阅图书");
        System.out.println("请输入你要借阅的图书");
        Scanner scanner=new Scanner(System.in);
        String borrowName=scanner.nextLine();
        int ret=bookshelf.getUseSize();
        for (int i = 0; i < ret; i++) {
            Book book=bookshelf.getBook(i);
            if (book.getBorrow()){
                System.out.println("这本书已经被借出");
                return;
            }
            if(book.getBookName().equals(borrowName)){
                book.setBorrow(true);
                System.out.println("借阅成功");
                return;
            }
        }
        System.out.println("没有你要的书");
    }
}
